import sympy as sym
import numpy as np
from collections.abc import Iterable
def has(exp,subexp):
    if(isinstance(exp,Iterable)):
        re = []
        sha = np.shape(exp)
        for item in np.array(exp).ravel():
                    flag = 0
                    for it in np.array(subexp).ravel():
                        if(item.has(it)):
                            re.append(1)
                            flag = 1
                            break
                    if(flag == 0):
                        re.append(0)    
        return np.array(re).reshape(sha)
    else:
            if(isinstance(subexp,Iterable)):
                flag = 0
                for it in np.array(subexp).ravel():
                    if(exp.has(it)):
                        return True
                return False
            else:
                if(exp.has(subexp)):
                    return True
                else:
                    return False       
x,y,z = sym.symbols("x y z")
exp = sym.sin(x) + sym.cos(x) + x**2
matrix =[[sym.sin(x)*sym.sin(y), sym.cos(x*y) + 1],[ sym.cos(x)*sym.tan(x), 2*sym.sin(x)**2]]
print(has(matrix,sym.sin(x)))
a = 1
print(has(x+1,[sym.sin(x), sym.cot(x), sym.exp(x)]))
print(has(exp,sym.cot(x)))